home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.undo;
-
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class CompoundEdit extends AbstractUndoableEdit {
- boolean inProgress = true;
- protected Vector edits = new Vector();
-
- public boolean addEdit(UndoableEdit anEdit) {
- if (!this.inProgress) {
- return false;
- } else {
- UndoableEdit last = this.lastEdit();
- if (last == null) {
- this.edits.addElement(anEdit);
- } else if (!last.addEdit(anEdit)) {
- if (anEdit.replaceEdit(last)) {
- this.edits.removeElementAt(this.edits.size() - 1);
- }
-
- this.edits.addElement(anEdit);
- }
-
- return true;
- }
- }
-
- public boolean canRedo() {
- return !this.isInProgress() && super.canRedo();
- }
-
- public boolean canUndo() {
- return !this.isInProgress() && super.canUndo();
- }
-
- public void die() {
- int size = this.edits.size();
-
- for(int i = size - 1; i >= 0; --i) {
- UndoableEdit e = (UndoableEdit)this.edits.elementAt(i);
- e.die();
- }
-
- super.die();
- }
-
- public void end() {
- this.inProgress = false;
- }
-
- public String getPresentationName() {
- UndoableEdit last = this.lastEdit();
- return last != null ? last.getPresentationName() : super.getPresentationName();
- }
-
- public String getRedoPresentationName() {
- UndoableEdit last = this.lastEdit();
- return last != null ? last.getRedoPresentationName() : super.getRedoPresentationName();
- }
-
- public String getUndoPresentationName() {
- UndoableEdit last = this.lastEdit();
- return last != null ? last.getUndoPresentationName() : super.getUndoPresentationName();
- }
-
- public boolean isInProgress() {
- return this.inProgress;
- }
-
- public boolean isSignificant() {
- Enumeration cursor = this.edits.elements();
-
- while(cursor.hasMoreElements()) {
- if (((UndoableEdit)cursor.nextElement()).isSignificant()) {
- return true;
- }
- }
-
- return false;
- }
-
- protected UndoableEdit lastEdit() {
- int count = this.edits.size();
- return count > 0 ? (UndoableEdit)this.edits.elementAt(count - 1) : null;
- }
-
- public void redo() throws CannotRedoException {
- super.redo();
- Enumeration cursor = this.edits.elements();
-
- while(cursor.hasMoreElements()) {
- ((UndoableEdit)cursor.nextElement()).redo();
- }
-
- }
-
- public String toString() {
- return super.toString() + " inProgress: " + this.inProgress + " edits: " + this.edits;
- }
-
- public void undo() throws CannotUndoException {
- super.undo();
- int i = this.edits.size();
-
- while(i-- > 0) {
- UndoableEdit e = (UndoableEdit)this.edits.elementAt(i);
- e.undo();
- }
-
- }
- }
-